package com.hemi.rhet;

import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.hemi.rhet.util.HttpUtil;

public class AskActivity extends Activity{

	private WebView mWebView;
	
	private Handler mHandler = new Handler();   
	private String defaultUrl = HttpUtil.buildUrl("/post/new");
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ask);
		
		mWebView = (WebView) findViewById(R.id.askPanel); 
		
        WebSettings webSettings = mWebView.getSettings();   
        webSettings.setDefaultTextEncodingName("utf-8"); 
        webSettings.setSavePassword(false);   
        webSettings.setSaveFormData(false);   
        webSettings.setJavaScriptEnabled(true);   
        webSettings.setSupportZoom(false);   
       // webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webSettings.setBuiltInZoomControls(false);
//        mWebView.setWebChromeClient(new MyWebChromeClient());  
//        mWebView.setWebViewClient(new MyWebViewClient());
        mWebView.setInitialScale(100);//初始显示比例100%
        mWebView.setMinimumHeight(100);
        mWebView.setMinimumWidth(100);
//        mWebView.addJavascriptInterface(new JavaScriptInterface2URL( ), "android_url");   
//        mWebView.addJavascriptInterface(new JavaScriptInterface2PostGuide(), "android_detail");   
        
//        mWebView.addJavascriptInterface(new JavaScriptInterfaceCallCarema(), "android_carema");   
//        mWebView.addJavascriptInterface(new JavaScriptInterface4POSTDataHttpClient( ), "android_post"); 
        JavaScriptInterfaceBinder.INSTANCE.addCallCaremaAblity(this, mWebView, mHandler);
        JavaScriptInterfaceBinder.INSTANCE.addWebDataPostAblity(this, mWebView, mHandler);
        JavaScriptInterfaceBinder.INSTANCE.addWebDataUrlRedirectAblity(this, mWebView, mHandler);
        JavaScriptInterfaceBinder.INSTANCE.addWebImageSelectAblity(this, mWebView, mHandler);
        mWebView.loadUrl(defaultUrl);   
	}
	
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
			if(data==null)
			{
				ParamUtil.showMessage(AskActivity.this, "无图片选择！");
				return ;
			}
			String message = (String)data.getExtras().get("imageInfo");
			HashMap ham = ParamUtil.stringTomsgMap(message);
			String  imageContainerId =  getIntent().getStringExtra("imageContainerId");
			String  fileIdItemName = getIntent().getStringExtra("fileIdItemName");
			mWebView.loadUrl("javascript:createImageSrc('"+ham.get("fileId")+"','"+ham.get("fileName")+"','"+imageContainerId+"','"+fileIdItemName+"')");
	}
	
	
	

}
